package edu.turtlekit2.warbot.agents;

import java.awt.Color;

import edu.turtlekit2.warbot.WarDynamicAgentsAbstract;
import edu.turtlekit2.warbot.exec.WarExplorerExec;
import edu.turtlekit2.warbot.message.SingletonMessage;

/**
 *
 * @author shyzk_000
 */
@SuppressWarnings("serial")
public class WarExplorer extends WarDynamicAgentsAbstract{

    private WarExplorerExec							_actionAgent = null;
    private final static int						_cost = 2000;
    private boolean									_messageInit = false;
    
    public WarExplorer(){
    	super("action");
    	_radius = 35;
    	_energy = 6000;
    }
    
    public WarExplorer(int t){    	
    	super("action");
    	_team = t;
    	_radius = 35;
    	_energy = 6000;
    }
    
    public void setup(){
    	playRole("WarExplorer");
    	if(_team == -1){
    		_team = getAttributes().getInt("team");
    		x = (int) (Math.random()*700);
    		y = (int) (Math.random()*300);
        	setXY(x, y);
    	}

        setHeading(Math.random()*360);
        setColor(Color.blue);
        _actionAgent = new WarExplorerExec(this);
        joinGroup(String.valueOf(getTeam()));
        requestRole(getTeam(), "WarExplorer", null);
    }

    public String getType() {
        return "WarExplorer";
    }

    public void setRandomHeading(){
        randomHeading();
    }

    /**
     * 
     * @return
     */
    public String action() {
    	if(!_messageInit){
    		_messageInit = true;
    		//On s'ajoute au gestionnaire de message
            //SingletonMessage.getInstance().addUser(mySelf(), getTeam(), getType());
    	}
        String retour = "";
        
        System.out.println(getType()+" "+getNumber()+" - "+xcor()+" / "+ycor()+" : "+getTeam()+" "+getEnergy()+"  "+getHeading());
        
        retour = _actionAgent.action();
        
        
        
        if(retour.equals("move")){
        	if(!isBlocked()){
            	fd(1);
            }
        }

        return "action";
    }

    
    /****************************************************************************
     * 																			*
     * 							   Fonctions Static								*
     * 																			*
     ****************************************************************************
     */
    
    public static final int getCost(){
		return _cost;
    }
}
